package com.example.music;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.Toast;
/**
 * 主页面，tabHost的实现已经播放按钮的布局
 * @author develop
 *
 */
public class MainActivity extends ActivityGroup implements OnClickListener{
	private TabHost tabHosts;
	private Button lastOne,pauseOrstart,nextOne;
	private String TAG="MainActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		tabHosts=(TabHost)findViewById(R.id.tabHost);
		tabHosts.setup(this.getLocalActivityManager());
//		tabHosts.setOnTabChangedListener(this);
		
		ImageButton btn1=new ImageButton(this);
		btn1.setBackgroundResource(R.drawable.bottom_book_button);
		tabHosts.addTab(tabHosts.newTabSpec("pageOne")
		.setIndicator(btn1)
		.setContent(new Intent(MainActivity.this, newestSong.class)));
		
		ImageButton btn2=new ImageButton(this);
		btn2.setBackgroundResource(R.drawable.bottom_book_button);
		tabHosts.addTab(tabHosts.newTabSpec("pageOne")
		.setIndicator(btn2)
		.setContent(new Intent(MainActivity.this, categoryOfSong.class)));
		
		ImageButton btn3=new ImageButton(this);
		btn3.setBackgroundResource(R.drawable.bottom_book_button); 
		tabHosts.addTab(tabHosts.newTabSpec("pageOne")
		.setIndicator(btn3)
		.setContent(new Intent(MainActivity.this, searchForSong.class)));
		
		ImageButton btn4=new ImageButton(this);
		btn4.setBackgroundResource(R.drawable.bottom_book_button);
		tabHosts.addTab(tabHosts.newTabSpec("pageOne")
		.setIndicator(btn4)
		.setContent(new Intent(MainActivity.this, myFavourite.class)));
			
		initView();
		listener();
	}

	private void listener() {
		// TODO Auto-generated method stub
		lastOne.setOnClickListener(this);
		pauseOrstart.setOnClickListener(this);
		nextOne.setOnClickListener(this);
	}

	

	private void initView() {
		// TODO Auto-generated method stub
		lastOne=(Button)findViewById(R.id.lastOne);
		pauseOrstart=(Button)findViewById(R.id.pauseOrstart);
		nextOne=(Button)findViewById(R.id.nextOne);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent it=new Intent();
		it.setAction(Intent.ACTION_EDIT);
		switch (v.getId()) {
		case R.id.lastOne:{
			Log.i(TAG, "lastOne");
			Toast.makeText(MainActivity.this, "lastOne", Toast.LENGTH_SHORT).show();
			it.setClass(MainActivity.this, MusicPlayer.class);
			it.putExtra("btnFlag", "lastOne");
			sendBroadcast(it);
			break;
		}
		case R.id.pauseOrstart:{
			Log.i(TAG, "pauseOrstart");
			Toast.makeText(MainActivity.this, "pauseOrstart", Toast.LENGTH_SHORT).show();
			it.setClass(MainActivity.this, MusicPlayer.class);
			it.putExtra("btnFlag", "pauseOrCreate");
			sendBroadcast(it);
			break;
		}
		case R.id.nextOne:{
			Log.i(TAG, "nextOne");
			Toast.makeText(MainActivity.this, "nextOne", Toast.LENGTH_SHORT).show();
			it.setClass(MainActivity.this, MusicPlayer.class);
			it.putExtra("btnFlag", "nextOne");
			sendBroadcast(it);
			break;
		}
		default:
			break;
		}
	}

	
}
